<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="1000px"
    :close-on-click-modal="false"
    :show-close="false"
    @open="handleOpen"
  >
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-no-more-click
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="cancel"
          >取消</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tempFileListT">
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="文件名" align="center" prop="fileName" />
      <el-table-column label="文件路径" align="center" prop="filePath" />
      <el-table-column
        label="更新时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-no-more-click
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleSelect(scope.row)"
            >选择</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { listTemplateFile } from "@/api/templateFile/templateFile";

export default {
  name: "TempFile",
  components: {},
  props: {
    open: {
      type: Boolean,
      default: false,
    },
    // 弹出层标题
    title: {
      type: String,
      default: "选择模板表格",
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓库物料明细表格数据
      tempFileListT: [],
      //   warehouseIdOptions: [],
      //   whRegionOptions: [],
      //   whLocationOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleOpen() {
      this.getList();
    },
    // //选择仓库处理函数
    // handleWarehouseChange(val) {
    //   this.queryParams.whRegionId = null;
    //   this.queryParams.whLocationId = null;
    //   if (val) {
    //     this.getWhRegionOpts(val);
    //   }
    // },
    // //选择库区处理函数
    // handleWhRegionChange(val) {
    //   this.queryParams.whLocationId = null;
    //   if (val) {
    //     this.getWhLocationOpts(val);
    //   }
    // },
    // //获取库区选项
    // getWhRegionOpts(val) {
    //   let queryParams = {
    //     warehouseId: val,
    //   };
    //   listWarehouseRegion(queryParams).then((res) => {
    //     this.whRegionOptions = res.rows;
    //   });
    // },
    // //获取库位选项
    // getWhLocationOpts(val) {
    //   let queryParams = {
    //     regionId: val,
    //   };
    //   listWarehouseLocation(queryParams).then((res) => {
    //     this.whLocationOptions = res.rows;
    //   });
    // },
    handleSelect(row) {
      this.$emit("onSelected", row);
    },
    /** 查询仓库物料明细列表 */
    getList() {
      this.loading = true;
      listTemplateFile(this.queryParams).then((response) => {
        this.tempFileListT = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.$emit("onCancel");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
